home *** CD-ROM | disk | FTP | other *** search
/ Power Programmierung / Power-Programmierung (Tewi)(1994).iso / magazine / pctchnqs / 1992 / number2 / vbplay / playnote.txt < prev    next >
Text File  |  1992-03-24  |  2KB  |  80 lines

  1. Function PlayNote%(nVoice%,nNote%,nTempo%,nDuration%,nMode%,nDot%)
  2.   Static fbaseFreq(12)
  3.   Static fMode!(3)
  4.  
  5.   '
  6.   ' Initialize arrays first time through
  7.   '
  8.   If fbaseFreq(0) < 1 Then
  9.     fbaseFreq(0) = 65.41
  10.     fbaseFreq(1) = 69.3
  11.     fbaseFreq(2) = 73.42
  12.     fbaseFreq(3) = 77.78
  13.     fbaseFreq(4) = 82.41
  14.     fbaseFreq(5) = 87.31
  15.     fbaseFreq(6) = 92.5
  16.     fbaseFreq(7) = 98#
  17.     fbaseFreq(8) = 103.83
  18.     fbaseFreq(9) = 110#
  19.     fbaseFreq(10) = 116.54
  20.     fbaseFreq(11) = 123.47
  21.  
  22.     fMode(S_STACCATO) = .75
  23.     fMode(S_NORMAL) = .875
  24.     fMode(S_LEGATO) = 1#
  25.   End If
  26.  
  27.   '
  28.   ' Check input values for validity
  29.   '
  30.   If nTempo% < 32 Or nTempo% > 255 Then
  31.     PlayNote% = S_SERDTP
  32.     Exit Function
  33.   End If
  34.  
  35.   If nNote% < 0 Or nNote% > 84 Then
  36.     PlayNote% = S_SERBDNT
  37.     Exit Function
  38.   End If
  39.  
  40.   If nDuration% < 0 Or nDuration% > 255 Then
  41.     PlayNote% = S_SERDLN
  42.     Exit Function
  43.   End If
  44.  
  45.   If nMode% < 0 Or nMode% > 2 Then
  46.     PlayNote% = S_SERDMD
  47.     Exit Function
  48.   End If
  49.  
  50.   '
  51.   ' Calcualte note duration parameters
  52.   '
  53.   If nDot% Then dt# = (3# ^ nDot%) / (2# ^ nDot%) Else dt# = 1#
  54.   nTicks% = 80000 / nTempo% / nDuration% * fMode(nMode%) * dt#
  55.  
  56.   '
  57.   ' Calculate frequency and play note
  58.   '
  59.   If nNote% = 0 Then
  60.     lFreq& = &H7F000000
  61.   Else
  62.     lFreq& = fbaseFreq(nNote% Mod 12) * (2^(nNote%\12))*65535
  63.   End If
  64.  
  65.   status% = SetVoiceSound(nVoice%, lFreq&, nTicks%)
  66.  
  67.   If status% <> 0 Then
  68.      PlayNote% = status%
  69.      Exit Function
  70.   End If
  71.  
  72.   '
  73.   ' If not legato, then play a rest to fill out note length
  74.   '
  75.   If nMode% <> S_LEGATO Then
  76.      nTicks% = 80000/nTempo%/nDuration%*(1#-fMode(nMode%))*dt#
  77.      PlayNote% = SetVoiceSound(nVoice%, &H7F000000, nTicks%)
  78.   End If
  79. End Function
  80.